# -*- coding: utf-8 -*-
"""
Utilities/Tornado Options/test01.py
"""
import os
import tornado.web
import asyncio
from tornado.options import options

options.define(name="port", default=8888, type=int, help="Process listen port.")
options.define(name="db_host", type=str, help="Process database host.", group="DataBase Settings")
options.define(name="db_port", type=int, help="Process database port.", group="DataBase Settings")
options.parse_command_line()


def parse_command_callback():
    print("Process parse command callback.")


async def main():
    config_path = os.path.join(os.path.dirname(__file__), "settings.py")
    options.parse_config_file(config_path)
    options.add_parse_callback(parse_command_callback)
    options.parse_command_line()
    options.print_help()

    print(options.items())
    print("-------------------------------------------------------")
    print(options.groups())
    print("-------------------------------------------------------")
    print(options.group_dict('DataBase Settings'))
    print("-------------------------------------------------------")
    print(options.as_dict())

    app = tornado.web.Application()
    app.listen(options.port)
    await asyncio.Event().wait()


if __name__ == '__main__':
    asyncio.run(main())
